<?php 
session_start();
$_SESSION['userurl'] = $_SERVER['REQUEST_URI'];
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<title>Document</title>
	<style>
		@media screen and (min-device-width:321px){
			header{
				background:red;
			}		

		}
		#detailsPicture img{
			width: 320px;
			height: 200px;
		}
		.dynamic-prop-table p img{
			width: 314px;
			padding-left: 3px;
		}
	</style>
	<link rel="stylesheet" href="./css/details.css" />
	<script src="./js/jquery-3.2.1.min.js"></script>
</head>

<body>
	<header id = "">
	</header>
	<section id = "header_search_box">
		<a href="./index.v.php" id = "header_search_index"></a>
		<span id ="span_myDetails">产品详情</span>
		<a href="./shoppingCart.v.php" id = "hsb_search_cart"></a>
		<a href="./myOrchard.v.php" id = "hsb_search_psonCenter"></a>
	</section>

	<?php 
		include('../api/detailsApi.php');
	 ?>
	

	<section id="sec_body">
		<div id="detailsPicture">
<!-- 			<img src="./images/2017-09-14_092025.gif" alt="" /> -->
			<?php 
				if($row){
					$tab='';
					$tab.=$row['img'];
					echo $tab;
				}
			 ?>
		</div>
		<div id="parameter">
<!-- 			<span id="goods_name">玫瑰女皇葡萄</span>
			<span id="specifications">规格：2斤 -->
			<?php 
				if($row){
					$tab='';
					$tab.=	'
							<span id="goods_name">'.$row['name'].'</span>
							<span id="specifications">规格：'.$row['nums'].''.$row['pcs'].'
							';
					echo $tab;
				}
			 ?>
				<div id="btn_number">
                    <span id="inC" onclick ="delNum(this)">-</span>
                    <input type="text" id="buy_number" disabled="" value="1" name="qty">
                    <span id="deC" onclick ="addNum(this)">+</span>
                </div>
			</span>
			<span id="settlement">
<!-- 				<span id="buy_number">￥58.00</span>
				<del id="buy_del">￥78.00</del> -->
				<?php 
					if($row){
						$tab='';
						$tab.=	'
								<span id="buy_price">￥'.$row['price'].'</span>
								';
						if($row['discount']){
						$tab.=	'
								<del id="buy_del">
								￥'.$row['discount'].'
								</del>
								';
						}
						$tab.="<input type='hidden' id='goods_id' value=".$row['id'].">";
						echo $tab;
					}
				 ?>
				<div id="btn_settlement">
					<button type="button" id="btn_addToCart" onclick="addToCart()" >加入购物车</button>
					<button type="button" id="btn_buy" onclick="buyGoods()">立即购买</button>
				</div>
			</span>
		</div>
		<div id="information">
			<div>
				<a href="javascript:void(0);"  id="goods_details">详细信息
				</a>
				<a href="javascript:void(0);" id="goods_evaluation" >用户评价
				</a>
			</div>

<!-- 			<ul id = "ul_attribute"> -->
<!-- 				<li >
					<span class="span_1">产地</span> <span class="span_2">中国</span>
				</li>
				<li >
					<span class="span_3">营养元素</span> <span class="span_4">果糖，花青素，维生素B12，果<br />酸</span>
				</li>
				<li >
					<span class="span_1">储藏方法</span> <span class="span_6">0°及以上冷藏</span>
				</li>
				<li >
					<span class="span_7">水果甜度</span> <span class="span_8">2星</span>
				</li> -->
				<div style="display: block;" class="dynamic-prop-table">
<!-- 					<dl><dt>产地</dt><dd>中国</dd></dl>
					<dl><dt>营养元素</dt><dd>果糖，花青素，维生素B12，果酸</dd></dl>
					<dl><dt>储藏方法</dt><dd>0°及以上冷藏</dd></dl>
					<dl><dt>水果甜度</dt><dd>3星</dd></dl> -->
					<?php 
						if($row){
							$res=unserialize($row['prototype']);
							$tab='';
							foreach ($res as $key => $value) {
								if (strlen($value)>0) {
									$tab.=	'
											<dl><dt>'.$key.'</dt><dd>'.$value.'</dd></dl>
										  	';
								}
							}
							echo $tab;
						}
					 ?>
					<?php 
						if($row){
							$tab='';
							$tab.=	
								htmlspecialchars_decode($row['cnt']);
									;
							echo $tab;
						}
					 ?>
				</div>				
<!-- 			</ul> -->
		</div>
		<div id="comments" style="display: none;">
			<a href="javascript:void(0);"  id="goods_details">详细信息
			</a>
			<a href="javascript:void(0);"  id="goods_evaluation">用户评价
			</a>
			<div id="evaluation_left">
				<img src="./images/2017-09-15_095520.gif" alt="" />
			</div>
			<ul id="evaluation_right">
				<li>
					<span class="span_left">很好:</span>
					<span class="span_right">98%</span>
					<div class="progressBar">
						<div id="bar_progress" role="progressbar" aria-valuenow="98" aria-valuemin="0" aria-valuemax="100" style="width: 98%;">
                    	</div>
					</div>
				</li>
				<li>
					<span class="span_left">一般:</span>
					<span class="span_right">1%</span>
					<div class="progressBar">
						<div id="bar_progress" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100" style="width: 1%;">
					</div>
				</li>
				<li>
					<span class="span_left">失望:</span>
					<span class="span_right">0%</span>
					<div class="progressBar">
						<div id="bar_progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
					</div>
				</li>	
			</ul>
			<ul id="evaluation_content">
				<li>
					<div>
						<span class="userName">136****8425</span>
						<sapn class="pull-right m-appraise-star">
							<i class="glyphicon fdayicon fdayicon-star-full"></i>
							<i class="glyphicon fdayicon fdayicon-star-full"></i>
							<i class="glyphicon fdayicon fdayicon-star-full"></i>
							<i class="glyphicon fdayicon fdayicon-star-full"></i>
							<i class="glyphicon fdayicon fdayicon-star-full"></i>
						</sapn>
					</div>
						<div class="m-appraise-content">好吃</div>
						<div class="m-appraise-data">2017-09-15 09:16:49
					</div>
				</li>
			</ul>
		</div>
	</section>

	<div class="m-component-float">
        <ul class="list-unstyled">
            <li id="goToTop" style="display: none;"><span class="glyphicon fdayicon fdayicon-toTop"></span></li>
            <li id="addCart"><span class="glyphicon fdayicon fdayicon-procart"></span></li>
        </ul>
    </div>
	<footer id="category_footer">
		<p>
			下载果园App，立享专属优惠<br />
			天天到家，2小时闪电送达
		</p>
		<span id="app_btn">立刻体验</span>
		<span id="app_close"></span>
	</footer>

	<script>
		$(function showInformation(){
			$("#comments #goods_details").click(function(){
				$("#comments").css('display','none')
				$("#information").css('display','block')
			})
		})
		$(function showInformation(){
			$("#information #goods_evaluation").click(function(){
				$("#information").css('display','none')
				$("#comments").css('display','block')
			})
		})
		$(function scroll(){
			$(window).scroll(function(){
				if($(window).scrollTop()>100){
					$("#goToTop").fadeIn(400)
				}else{
					$("#goToTop").fadeOut(400)
				}
			})
			$("#goToTop").click(function(){
				$("body").animate({scrollTop:0},500)
			})
		})
		function delNum(ts){
			var obj_delNumber = $(ts).parent().children().eq(1).val()
			if(obj_delNumber > 1){
				obj_delNumber = parseInt(obj_delNumber)-1
				$(ts).parent().children().eq(1).val(obj_delNumber)
			}
		}
		function addNum(ts){
			var obj_addNumber = $(ts).parent().children().eq(1).val()
			obj_addNumber = parseInt(obj_addNumber)+1
			$(ts).parent().children().eq(1).val(obj_addNumber)
		}
		function addToCart(){
			var id =$("#goods_id").val()
			var num=$("#buy_number").val()
			var price=$("#buy_price").text()
			var name=$("#goods_name").text()
			price=price.substr(1)
			$.get('../api/shopCartApi.php',{'act':'addGoodsToShopCart','id':id,'name':name,'price':price,'num':num},function(data){
				// alert(data)
				if(data.code==100){
					alert(data.msg)
					window.location.href="./quick_login.v.php"
				}else{
					// alert(data.msg)
				}
			},'json')
		}
		function buyGoods(){
			var id =$("#goods_id").val()
			var num=$("#buy_number").val()
			var price=$("#buy_price").text()
			var name=$("#goods_name").text()
			price=price.substr(1)
			$.get('../api/shopCartApi.php',{'act':'addGoodsToShopCart','id':id,'name':name,'price':price,'num':num},function(data){
				// alert(data)
				if(data.code==100){
					alert(data.msg)
					window.location.href="./quick_login.v.php"
				}else{
					// alert(data.msg)
					window.location.href="./shoppingCart.v.php"
				}
			},'json')			
		}
	</script>
</body>
</html>